package com.fourthGroup.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class CouponProducer {
    
    @Autowired
    private StreamBridge streamBridge;
    
    private static final String GRAB_COUPON_BINDING = "grabCoupon-out-0";
    
    /**
     * 发送抢购优惠券消息
     */
    public void sendGrabCouponMessage(Integer userId, Long couponId) {
        Map<String, Object> message = new HashMap<>();
        message.put("userId", userId);
        message.put("couponId", couponId);
        
        boolean result = streamBridge.send(GRAB_COUPON_BINDING, message);
        log.info("发送抢购优惠券消息: userId={}, couponId={}, 结果: {}", userId, couponId, result);
    }
} 